package org.dragon.mappers;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.dragon.models.Credential;

/**
 * Author:     Zhao Yan
 * DateTime:   2023/5/17 12:08
 */
@Mapper
public interface CredentialExtendMapper extends CredentialMapper {

    @Select("SELECT * FROM credential WHERE source = #{source} AND source_id = #{source_id}")
    @Results({
            @Result(column="id", property="id", jdbcType= JdbcType.VARCHAR, id=true),
            @Result(column="account_id", property="accountId", jdbcType=JdbcType.VARCHAR),
            @Result(column="source", property="source", jdbcType=JdbcType.VARCHAR),
            @Result(column="source_id", property="sourceId", jdbcType=JdbcType.VARCHAR),
            @Result(column="source_nick", property="sourceNick", jdbcType=JdbcType.VARCHAR),
            @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Credential findBySourceAndSourceId(@Param("source") String source, @Param("source_id") String source_id);

    @Update("UPDATE credential SET account_id = #{accountId} WHERE id = #{id}")
    int updateAccountId(Credential credential);
}
